app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    /* 岗位清单 */
    .state('position', {
      url: '/position',
      templateUrl: 'app/partials/position/index.html',
      controller: function($scope,$location,Position) {
        $scope.widget_title = '岗位管理';
        $scope.positions = Position.query();
        
        $scope.itemDelete = function(item){
          Position.delete({},{"id": $scope.positions[item].id})
          $scope.positions.splice(item, 1); 
        }
        $scope.itemEdit = function(item){
          $location.url("/position/edit/"+item)
        }

        $scope.edit_position_standard = function(item){
          $location.url("/position/position_certificate_standard/" + item)
        }
     }
    })
   /*添加岗位*/
  .state('position.new', {
      url: '/new',
      templateUrl: 'app/partials/position/form.html',
      controller: function($scope,$state,Position,Nature) {
        $scope.widget_title = '添加岗位';
        $scope.natures = Nature.query();
        
        $scope.update = function(position){
          Position.save(position,function(nr){
            $scope.positions.push(nr["result"]);
          });
          
          $scope.position = {};
          $state.go('position');
        }
     }
    })
   /* 编辑 岗位 */
    .state('position.edit', {
      url: '/edit/:id',
      templateUrl: 'app/partials/position/form.html',
      controller: function($scope,$state,$stateParams,Position,Nature) {
        $scope.widget_title = '编辑岗位';
        $scope.position =  Position.get({id: $stateParams.id});
        $scope.natures = Nature.query();

        $scope.update = function(position){
          Position.update(position);
          $state.transitionTo('position',$stateParams,{reload: true});
        }
     }
    })
  })